/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaPrincipal1.java
 *
 * Created on Nov 23, 2011, 1:28:38 AM
 */
package br.fesppr.sacob.gui;

import br.fesppr.sacob.Sacob;
import br.fesppr.sacob.dao.AtendimentoDAO;
import br.fesppr.sacob.dto.AtendimentoDTO;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author chrestenzen
 */
public class TelaPrincipal extends javax.swing.JFrame {

  
    

    /** Creates new form TelaPrincipal1 */
    public TelaPrincipal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblTxt = new javax.swing.JLabel();
        lblTxt2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblChamado = new javax.swing.JTable();
        btnAtt = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        mnuPrinc = new javax.swing.JMenuBar();
        menuSacob = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        menuChamado = new javax.swing.JMenu();
        menuNovoChamado = new javax.swing.JMenuItem();
        menuFinalizarChamado = new javax.swing.JMenuItem();
        menuCliente = new javax.swing.JMenu();
        menuNovoCliente = new javax.swing.JMenuItem();
        menuConCliente = new javax.swing.JMenuItem();
        menuConsultar = new javax.swing.JMenu();
        menuConsultaBanco = new javax.swing.JMenuItem();
        menuSobre = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SACOB -  Principal");
        setResizable(false);

        lblTxt.setFont(new java.awt.Font("DejaVu Sans", 1, 12));
        lblTxt.setForeground(new java.awt.Color(3, 3, 3));
        lblTxt.setText("SACOB - Sistema de Atendimento ao Cliente Belíssima ");

        lblTxt2.setFont(new java.awt.Font("Tahoma", 0, 10));
        lblTxt2.setText("Atendimentos Pendentes/Emergênciais :");

        tblChamado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Protocolo", "Status", "Cliente", "Descrição", "Produto", "Prioridade", "Data"
            }
        ));
        tblChamado.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                tblChamadoVetoableChange(evt);
            }
        });
        jScrollPane1.setViewportView(tblChamado);

        btnAtt.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        btnAtt.setText("Listar Atendimentos Pedentes");
        btnAtt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAttActionPerformed(evt);
            }
        });

        mnuPrinc.setMaximumSize(new java.awt.Dimension(318, 900));

        menuSacob.setText("Sacob");

        jMenuItem1.setText("Trocar de Usuário");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menuSacob.add(jMenuItem1);

        jMenuItem2.setText("Sair");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        menuSacob.add(jMenuItem2);

        mnuPrinc.add(menuSacob);

        menuChamado.setText("Chamados");

        menuNovoChamado.setText("Novo Chamado");
        menuNovoChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuNovoChamadoActionPerformed(evt);
            }
        });
        menuChamado.add(menuNovoChamado);

        menuFinalizarChamado.setText("Finalizar Chamado");
        menuFinalizarChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuFinalizarChamadoActionPerformed(evt);
            }
        });
        menuChamado.add(menuFinalizarChamado);

        mnuPrinc.add(menuChamado);

        menuCliente.setText("Clientes\n");

        menuNovoCliente.setText("Cadastrar Novo Cliente");
        menuNovoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuNovoClienteActionPerformed(evt);
            }
        });
        menuCliente.add(menuNovoCliente);

        menuConCliente.setText("Editar Cliente");
        menuConCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuConClienteActionPerformed(evt);
            }
        });
        menuCliente.add(menuConCliente);

        mnuPrinc.add(menuCliente);

        menuConsultar.setText("Relatórios");

        menuConsultaBanco.setText("Relatórios");
        menuConsultaBanco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuConsultaBancoActionPerformed(evt);
            }
        });
        menuConsultar.add(menuConsultaBanco);

        mnuPrinc.add(menuConsultar);

        menuSobre.setText("Sobre");

        jMenuItem3.setText("Sobre o Sacob");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        menuSobre.add(jMenuItem3);

        mnuPrinc.add(menuSobre);

        setJMenuBar(mnuPrinc);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addComponent(lblTxt))
            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 475, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTxt2))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnAtt))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(lblTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblTxt2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAtt)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
      int i = JOptionPane.showConfirmDialog(this, "Tem certeza que deseja sair?", "Sair?", JOptionPane.YES_NO_OPTION);
      if(i == JOptionPane.YES_OPTION)
      {
          System.exit(0);
      }
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void menuNovoChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNovoChamadoActionPerformed
        // TODO add your handling code here:
         if(novoChamado == null || !novoChamado.isVisible()){
            novoChamado = new NovoChamado();
            novoChamado.setVisible(true);
        }
}//GEN-LAST:event_menuNovoChamadoActionPerformed

private void menuFinalizarChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFinalizarChamadoActionPerformed

        // TODO add your handling code here:
        if(finalizarChamado == null || !finalizarChamado.isVisible()){
            finalizarChamado = new FinalizarChamado(this, true);
            finalizarChamado.setVisible(true);
         }
}//GEN-LAST:event_menuFinalizarChamadoActionPerformed

private void menuNovoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNovoClienteActionPerformed
        // TODO add your handling code here:
        if(novoCliente == null || !novoCliente.isVisible()){
            novoCliente = new NovoCliente();
            novoCliente.setVisible(true);
         }
}//GEN-LAST:event_menuNovoClienteActionPerformed

private void menuConClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuConClienteActionPerformed
        // TODO add your handling code here:
        if( editarCliente == null || !editarCliente.isVisible())
        {
           editarCliente = new EditarCliente();
            editarCliente.setVisible(true);
        }
}//GEN-LAST:event_menuConClienteActionPerformed

private void menuConsultaBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuConsultaBancoActionPerformed
        // TODO add your handling code here:
        if (relatorios == null || !relatorios.isVisible()) {
            relatorios = new Relatorios();
            relatorios.setVisible(true);
      }
}//GEN-LAST:event_menuConsultaBancoActionPerformed

private void tblChamadoVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_tblChamadoVetoableChange
// TODO add your handling code here:
}//GEN-LAST:event_tblChamadoVetoableChange

private void btnAttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAttActionPerformed
// TODO add your handling code here:
    AtendimentoDTO dtoa = new AtendimentoDTO();
    AtendimentoDAO daoa = new AtendimentoDAO();
        ArrayList<AtendimentoDTO> listaAtendimento = daoa.listaAtendimento();
    
    DefaultTableModel modelo = (DefaultTableModel) tblChamado.getModel();
       
    while(modelo.getRowCount() > 0)
    {
        modelo.removeRow(0);
    }
    
//    for(int linha = 0; linha < modelo.getRowCount(); linha++)
//    {
//        modelo.removeRow(linha);
//    }
    
    for (AtendimentoDTO atendimento : listaAtendimento) 
    {
        Object[] o = {String.valueOf(atendimento.getProtocolo()), atendimento.getStatus(),atendimento.getNomeCliente(), atendimento.getDescricao(), atendimento.getProduto(), atendimento.getPrioridade(), atendimento.getData()};
        modelo.addRow(o);
    }
    
    
    
    
}//GEN-LAST:event_btnAttActionPerformed

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
                if( telaLogin == null || !telaLogin.isVisible())
                 telaLogin = new TelaLogin();
                 telaLogin.setVisible(true);
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
// TODO add your handling code here:
        if (sobreSacob == null || !sobreSacob.isVisible())
            sobreSacob = new SobreSacob();
            sobreSacob.setVisible(true);
}//GEN-LAST:event_jMenuItem3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TelaPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAtt;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblTxt;
    private javax.swing.JLabel lblTxt2;
    private javax.swing.JMenu menuChamado;
    private javax.swing.JMenu menuCliente;
    private javax.swing.JMenuItem menuConCliente;
    private javax.swing.JMenuItem menuConsultaBanco;
    private javax.swing.JMenu menuConsultar;
    private javax.swing.JMenuItem menuFinalizarChamado;
    private javax.swing.JMenuItem menuNovoChamado;
    private javax.swing.JMenuItem menuNovoCliente;
    private javax.swing.JMenu menuSacob;
    private javax.swing.JMenu menuSobre;
    private javax.swing.JMenuBar mnuPrinc;
    private javax.swing.JTable tblChamado;
    // End of variables declaration//GEN-END:variables
    private NovoChamado novoChamado;
    private FinalizarChamado finalizaChamado;
    private NovoCliente novoCliente;
    private EditarCliente editarCliente;
    private FinalizarChamado finalizarChamado;
    private TelaLogin telaLogin;
    private SobreSacob sobreSacob;
    private Relatorios relatorios;
    //private ConsultaRapida consultaRapida;
}
